import { getCode } from '@/api/login.js';
import { v4 as uuidv4 } from 'uuid';

export default {
  methods: {
    async _getCode () {
      const sid = this.$store.state.sid;
      // console.log(sid);
      const res = await getCode(sid);
      if (res.code === 200) {
        this.svg = res.data;
      }
    },
    setSid () {
      let sid = '';
      if (localStorage.getItem('sid')) {
        sid = localStorage.getItem('sid');
      } else {
        sid = uuidv4();
        localStorage.setItem('sid', sid);
      }
      this.$store.commit('setSidValue', sid);
    }
  },
  mounted () {
    // 获取图片验证码的sid
    this.setSid();
    // 获取图片验证码
    this._getCode();
  }
};
